<?php

class application_forms_Register extends Zend_Form{

public $name; 
public $firstname;
public $lastname;
public $email;
public $password;
public $password2;
public $sex;
public $countryList;
public $city;
public $anniv;


public function __construct($options = null){
 
        parent::__construct($options);
         
        // initialize form
        $this->setName('registration')
        ->setAction('register')
        ->setMethod('post');
		
		$emptyValidator = new Zend_Validate_NotEmpty();
		$emptyValidator->setMessage(("All the fields are required"));

		$emailValidator = new Zend_Validate_EmailAddress();
		$emailValidator->setMessage(('E-mail must be a valid'));

		$primaryValidator = new Zend_Validate_Db_NoRecordExists('Profiles', 'Email');
		$primaryValidator->setMessage(("E-mail adress already in use"), Zend_Validate_Db_Abstract::ERROR_RECORD_FOUND);

		$stringLengthValdiator = new Zend_Validate_StringLength(6, 12);
		$stringLengthValdiator->setMessage(('Password must have 6 to 12 caracters'));
		
		
		$this->name = new Zend_Form_Element_Text('username');
        $this->name	->setLabel(('Username'))
				->setAttrib('size', 40)
				->setAttrib('class', 'inputbox required')
				->setAttrib('maxlength', 50)
				->setAttrib('id', 'username')
				->setRequired(true)
				->addFilter('StripTags')
        		->addFilter('StringTrim')
        		->addValidator($emptyValidator)
				->addValidator(new Zend_Validate_Alnum());

        $this->lastname = new Zend_Form_Element_Text('lastname');
        $this->lastname 	->setLabel(('Lastname'))
				
				->setAttrib('size', 40)
				->setAttrib('class', 'inputbox required')
				->setAttrib('maxlength', 50)
				
				->setAttrib('id', 'lastname')
				->setRequired(true)
				->addFilter('StripTags')
        		->addFilter('StringTrim')
        		->addValidator($emptyValidator);


        $this->firstname = new Zend_Form_Element_Text('firstname');
        $this->firstname	->setLabel(('Firstname'))
				
				->setAttrib('size', 40)
				->setAttrib('class', 'inputbox required')
				->setAttrib('maxlength', 50)
				->setAttrib('id', 'firstname')
				->setRequired(true)
				->addFilter('StripTags')
        		->addFilter('StringTrim')
        		->addValidator($emptyValidator);

				
		$this->email = new Zend_Form_Element_Text('email');
		$this->email	->setLabel(('E-mail'))
				->setAttrib('size', 40)
				->setAttrib('class', 'inputbox required validate-email')
				->setAttrib('maxlength', 100)
				->setAttrib('id', 'email')
				->setRequired(true)
				->addFilter('StripTags')
        		->addFilter('StringTrim')
        		->addValidator($emailValidator)
        		->addValidator($primaryValidator)
        		->addValidator($emptyValidator);
				
	
				
		$this->password = new Zend_Form_Element_Password('password');
		$this->password	->setLabel(('Password'))
				->setAttrib('size', 40)
				->setAttrib('class', 'inputbox required validate-password')
				->setAttrib('maxlength', 100)
				->setAttrib('id', 'password')
				->setRequired(true)
        		->addValidator($emptyValidator);
				
	$this->password2 = new Zend_Form_Element_Password('password2');
    $this->password2	->setLabel(('Password'))
				->setAttrib('size', 40)
				->setAttrib('class', 'inputbox required validate-passverify')
				->setAttrib('maxlength', 100)
				->setAttrib('id', 'password2')
				->setRequired(true)
				->addValidator($emptyValidator);
        		if (isset($_POST['password'])) {
            		$passwordVerificationValidator = new Zend_Validate_Identical($_POST['password']);
            		$passwordVerificationValidator	->setMessage(('Password does not match !'));
            		$this->password2->addValidator($passwordVerificationValidator);
        		}
				
	$this->sex = new Zend_Form_Element_Select('sex');
	$this->sex	->setLabel(('Sexe'))
				->setAttrib('id', 'sex')
				->setAttrib('style', 'width:315px')
				->setRequired(true)
				->addValidator($emptyValidator);

				$this->sex->addMultiOption("","Please select...");
				$this->sex->addMultiOption("male","Male");
				$this->sex->addMultiOption("female","Female");
				
	$q = Doctrine_Query::create()
	   ->from('Nacos_Model_Countries');
	   $results = $q->execute();
			   
	$this->countryList = new Zend_Form_Element_Select('country');
	$this->countryList->setLabel(('Country'))
				->setAttrib('id', 'country')
				->setAttrib('style', 'width:315px')
				->addValidator($emptyValidator);
				
	$this->countryList->addMultiOption("", 'Please select...');
	foreach ($results as $oCountry) {
		$this->countryList->addMultiOption($oCountry['ISO2'], $oCountry['Country']);
	}
	
	$this->city = new Zend_Form_Element_Text('city');
	$this->city	->setLabel(('City'))
			
			->setAttrib('size', 40)
			->setAttrib('class', 'inputbox required')
			->setAttrib('maxlength', 50)
			->setAttrib('id', 'city')
			->setRequired(true)
			->addFilter('StripTags')
			->addFilter('StringTrim')
			->addValidator($emptyValidator);
			
	$this->anniv = new Zend_Form_Element_Text('anniv');
	$this->anniv	->setLabel(('Birthday(yyyy-mm-dd)'))
			->setAttrib('size', 40)
			->setAttrib('class', 'inputbox required')
			->setAttrib('maxlength', 50)
			->setAttrib('id', 'anniv')
			->setRequired(true)
			->addFilter('StripTags')
			->addFilter('StringTrim')
			->addValidator($emptyValidator);

				
				
		$submit = new Zend_Form_Element_Submit('register');
        $submit->setAttrib('class', 'button validate')
        ->setLabel(('Register'));
				
		 // create captcha
        $captcha = new Zend_Form_Element_Captcha('captcha', array(
			'captcha' => array(
				'captcha' => 'Image',
				'wordLen' => 5,
				'timeout' => 300,
				'width' => 170,
				'height' => 60,
				'imgUrl' => 'http://jetcamer.com/nna/captcha',
				'imgDir' => '/home/jetcamer/public_html/nna/captcha',
				'LineNoiseLevel' => '0',
				'DotNoiseLevel' =>'0',
				'font' => '/home/jetcamer/public_html/nna/captcha/LiberationSansRegular.ttf',
			)
		));
        $captcha->setLabel('Verification:');
        

		$this->addElements(array($this->name, $this->firstname, $this->lastname, $this->email,$this->password, $this->password2, $this->sex, $this->countryList, $this->city, $this->anniv, $captcha, $submit));
	}
}